#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: shijianbo
@Email:
@Time: 2023/4/13 10:33
@File: download.py
"""
import os
from pyartifactory import Artifactory

class GetPackage(object):
    def __init__(self):
        self.url='http://package.hundsun.com/artifactory'
        # self.username='caozy33405'
        # self.password='AKCp8mZwMruHSFpnXoXNt4nPLAbJeyN4owk2WJsYv59dA3erStMhQyBFiph9iWorfAj7W3hpq'
        # 密码:域帐号名-hundsunSSO
        self.username='caozy33405'    
        self.password='AKCp8mZwMruHSFpnXoXNt4nPLAbJeyN4owk2WJsYv59dA3erStMhQyBFiph9iWorfAj7W3hpq'
        self.art = Artifactory(url=self.url, auth=(self.username, self.password))

    def get_repo_list(self):
        """
        获取可用仓库名称
        :return: repo_list
        """
        repo_list = []
        repo_list_tamp = self.art.repositories.list()
        for repo in repo_list_tamp:
            repo_list.append(repo.key)
        return repo_list

    def get_job_list(self, repo=''):
        """
        获取可用job名称
        :return: job_list
        """
        job_list = []
        job_list_tamp = self.art.artifacts.info(repo).children
        for job in job_list_tamp:
            if job.uri[1:] in ('temp','sftp'):
                continue
            job_list.append(job.uri[1:])
        return job_list

    def download_file(self,src,des=''):
        """
        下载固件
        :param: src: 固件地址，从仓库名称开始，不带url
        :param: des: 下载文件夹，不带文件名称
        """
        des = os.path.join(os.path.dirname(__file__), f'download\\{des}')
        self.art.artifacts.download(src,des)

if __name__ == '__main__':
    t = GetPackage()
    t.download_file(src='ics4.0-generic-testUnit-local/ICS4.0/os/ICS4.0V202301/ICS4.0V202301.0.0/WEB/ICS4.0-management-V202301-0-0.zip')